package  
{
	import com.greensock.TweenMax;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.utils.getDefinitionByName;
	/**
	 * ...
	 * @author ...
	 */
	public class DialUI extends Sprite 
	{
		private var _tween:TweenMax;
		private var _view:*;
		
		//物品个数;
		private var _count:int = 8;
		//角度;
		private var _angle:Number = 360/_count;
		//最少旋转圈数;
		private var _rotateNum:int = 2;
		
		public function DialUI() 
		{
			initView();
		}
		
		private function initView():void
		{
			var cls:Class = getDefinitionByName("Dial") as Class;
			if (cls != null)
			{				
				_view = new cls();
				_view.pointer.rotation = 0;
				_view.btnStart.addEventListener(MouseEvent.CLICK, onClickHandler);				
				addChild(_view);
				
				_tween = new TweenMax(_view.pointer, 2, {onComplete: onCompleteHandler});
			}
		}
		
		private function onClickHandler(evt:MouseEvent):void
		{
			_view.btnStart.mouseEnabled = false;
			var temp:uint = Math.floor(8 * Math.random());
			trace(temp);
			var rt:Number = _angle * temp + (360 * _rotateNum);
			_tween.updateTo({rotation: rt}, true)
		}
		
		private function onCompleteHandler():void
		{
			_view.btnStart.mouseEnabled = true;
		}
	}
	
}